package com.example.demo.ai;

import cn.dev33.satoken.util.SaResult;
import dev.langchain4j.model.openai.OpenAiChatModel;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName OpenAIController
 * @Description openAI接口
 * @Author MingChang.Wei
 * @Date 2025/8/5
 **/
@RestController
@RequestMapping("/open/api")
@Tag(name = "AI智能服务", description = "OpenAI集成接口")
public class OpenAIController {

    /**
     * AI聊天
     *
     * @param content 问题
     * @return 回答内容
     */
    @RequestMapping("/chat")
    @Operation(summary = "AI智能对话", description = "与AI进行智能对话交流")
    public SaResult chat(@RequestParam String content) {
        OpenAiChatModel model = OpenAiChatModel.builder()
                .baseUrl("http://langchain4j.dev/demo/openai/v1")
                .apiKey("demo")
                .modelName("gpt-4o-mini")
                .build();
        return SaResult.data(model.chat(content));
    }
}
